package cn.hanyx.coder.design.pattern.structural.bridge.demo02;

import cn.hanyx.coder.design.pattern.structural.bridge.demo02.handler.ErrorAlertHandler;
import cn.hanyx.coder.design.pattern.structural.bridge.demo02.handler.TimeoutTpsAlerthandler;
import cn.hanyx.coder.design.pattern.structural.bridge.demo02.handler.TpsAlertHandler;
import cn.hanyx.coder.design.pattern.structural.bridge.demo02.notify.NormalNotification;
import cn.hanyx.coder.design.pattern.structural.bridge.demo02.notify.ServerNotification;
import cn.hanyx.coder.design.pattern.structural.bridge.demo02.notify.TrivialNotification;
import cn.hanyx.coder.design.pattern.structural.bridge.demo02.sender.MailMsgSender;
import cn.hanyx.coder.design.pattern.structural.bridge.demo02.sender.PhoneMsgSender;
import cn.hanyx.coder.design.pattern.structural.bridge.info.AlertRule;

/**
 * ApplicationContext
 *
 * @author hanyx
 * @date 2020/05/19
 */
public class ApplicationContext {
    private static final ApplicationContext instance = new ApplicationContext();

    public static ApplicationContext getInstance() {
        return instance;
    }

    private ApplicationContext() {
        this.initializeBeans();
    }

    private AlertRule alertRule;
    private Alert02 alert;

    public void initializeBeans() {
        alertRule = new AlertRule();
        //省略一些初始化代码
        alert = new Alert02();

        alert.addAlertHandler(new TpsAlertHandler(alertRule, new NormalNotification(new MailMsgSender())));
        alert.addAlertHandler(new ErrorAlertHandler(alertRule, new ServerNotification(new PhoneMsgSender())));
        alert.addAlertHandler(new TimeoutTpsAlerthandler(alertRule, new TrivialNotification(new MailMsgSender())));
    }

    public Alert02 getAlert() {
        return alert;
    }


}
